{% extends "base.html" %}
{% load extended_filter %}
{% load humanize %}

{% block content %}
    <div class="row">
        <div class="span12">
            <h3>Total {{ tables|length}} User Table</h3>
            <table class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                    <th>table</th>
                    <th>cluster</th>
                    <th>data amount(MB)</th>
                    <th>read qps</th>
                    <th>write qps</th>
                    <th><a href="/monitor/table/count_rows">count rows<a></th>
                    <th>last update time</th>
                </tr>
                </thead>
                <tbody>
                {% for table in tables %}
                    <tr>
                        <td><a href="/monitor/table/{{ table.id }}">{{ table.name }}</a></td>
                        <td><a href="/monitor/cluster/{{ table.cluster.id }}/table">{{ table.cluster.name }}</a></td>
                        <td>{{ table.memStoreSizeMB|add:table.storefileSizeMB | intcomma}}</td>
                        <td>{{ table.readRequestsCountPerSec | floatformat}}</td>
                        <td>{{ table.writeRequestsCountPerSec| floatformat }}</td>
                        <td>
                          {% if table.is_count_rows %}
                            {{ table.rows }}
                          {% else %}
                            <button class="btn" onclick="confirm_add_to_count({{ table.id }})");">Add to count</button>
                          {% endif %}
                        </td>
                        <td>{{ table.last_update_time }}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    <script type="text/javascript">
      function confirm_add_to_count(table_id) {
        if(confirm("Confirm add to count?")) {
          var xmlhttp;
          if (window.XMLHttpRequest) {
            xmlhttp=new XMLHttpRequest(); // for IE7+, Firefox, Chrome, Opera, Safari
          } else {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // for IE6, IE5
          }
          xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
              location.reload();
            }
          }
          xmlhttp.open("GET","/monitor/table/add_count_rows/"+table_id, true);
          xmlhttp.send();
        }else{
          // do nothing
        }
      }
    </script>
{% endblock %}
